package com.mb.fabric.hongda.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PreDestroy;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @program: Fabric-http
 * @Description: 容器用到的bean
 * @author: wys1890
 * @create: 2020-11-09 11:15
 **/
@Configuration
public class BeanConfig {
    
    private ExecutorService executorService;
    
    @Bean
    public ExecutorService executorService() {
        int cpuN = Runtime.getRuntime().availableProcessors();
        executorService = new ThreadPoolExecutor(cpuN << 1, cpuN << 1, 30L,
                TimeUnit.SECONDS, new LinkedBlockingQueue<>(2048));
        return executorService;
    }
    
    
    @PreDestroy
    public void destroy() {
        executorService.shutdownNow();
    }
}
